package org.monkey4j.runner;

import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.monkey4j.StatementFactory;

/**
 * {@link BlockJUnit4ClassRunner} implementation which used as a delegate to run monkey related testing functionaliy.
 * 
 * @author hillger.t
 */
class Monkey4jRunnerDelegate extends BlockJUnit4ClassRunner {
	private final StatementFactory statementFactory;

	public Monkey4jRunnerDelegate(final Class<?> testClass) throws InitializationError {
		super(testClass);
		statementFactory = new StatementFactory(testClass);
	}

	@Override
	protected Statement methodInvoker(FrameworkMethod method, Object runningTest) {
		Statement statement = super.methodInvoker(method, runningTest);

		return statementFactory.newRepetitiveStatement(runningTest, statement);
	}
}
